/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.ac.iie.di.ban.news.server.check.checkers;

import cn.ac.iie.di.ban.news.server.check.CheckResult;
import cn.ac.iie.di.ban.news.server.check.Checker;

/**
 *
 * @author zwlin
 */
public class IntegerRangeChecher implements Checker<String, Integer> {

	@Override
	public CheckResult check(String src, Integer target) {
		if (target == null || target < 0) {
			return new CheckResult();
		}
		try {
			int i = Integer.parseInt(src);
			if (0 <= i && i <= target) {
				return new CheckResult();
			} else {
				return new CheckResult("value out of range.");
			}
		} catch (Exception e) {
			return new CheckResult("not int value.");
		}
	}

}
